using System;
using System.Drawing;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Diagnostics;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;using THSERP.BusinessEntities;using THSERP.BaseProvider;
using DevExpress.XtraEditors;
using THSLib;using THSERP.BaseProvider;

namespace THSERP.Modules.Shipment
{
    /// <summary>
    /// Summary description for guiSelectSaleOrder.
    /// </summary>
    public class guiSelectTransfer : THSERPScreen
    {
        private DevExpress.XtraGrid.GridControl fld_dgcSaleOrders;
        private DevExpress.XtraGrid.Views.Grid.GridView fld_dgvSaleOrders;
        private DevExpress.XtraGrid.Columns.GridColumn colARSaleOrderNo;
        private DevExpress.XtraGrid.Columns.GridColumn colARSaleOrderMatchCode01;
        private DevExpress.XtraGrid.Columns.GridColumn colARSaleOrderMatchCode02;
        private SimpleButton fld_btnOK;
        private SimpleButton fld_btnCancel;
        private DevExpress.XtraGrid.Columns.GridColumn colCustomerName;
        private DevExpress.XtraGrid.Columns.GridColumn colSelect;
        private DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit repItemCheckEditSelect;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;
        private DevExpress.XtraGrid.Columns.GridColumn colARSaleOrderID;
        private DevExpress.XtraGrid.Columns.GridColumn colFK_ARCustomerID;
        private Label label1;
        private TextEdit fld_txtARSaleOrderNo;
        private Label label3;
        private TextEdit fld_txtARSaleOrderMC1;
        private Label label4;
        private TextEdit fld_txtARSaleOrderMC2;
        private SimpleButton fld_txtSearch;
        private Label label5;
        private DateEdit fld_dteARSaleOrderStartDateFrom;
        private DateEdit fld_dteARSaleOrderStartDateTo;
        private Label label6;
        private DateEdit fld_dteARSaleOrderDeliveryDateTo;
        private Label label7;
        private DateEdit fld_dteARSaleOrderDeliveryDateFrom;
        private Label label8;

        
        private String _shipmentType;
        private DevExpress.XtraGrid.Columns.GridColumn colARSaleOrderStatus;
        private DevExpress.XtraGrid.Columns.GridColumn colLockStatus;
        

        private SaleOrder.SaleOrderSearchObject _saleOrderSearchObject = new Modules.SaleOrder.SaleOrderSearchObject();

        public guiSelectTransfer()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(guiSelectTransfer));
            this.fld_dgcSaleOrders = new DevExpress.XtraGrid.GridControl();
            this.fld_dgvSaleOrders = new DevExpress.XtraGrid.Views.Grid.GridView();
            this.colSelect = new DevExpress.XtraGrid.Columns.GridColumn();
            this.repItemCheckEditSelect = new DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit();
            this.colARSaleOrderID = new DevExpress.XtraGrid.Columns.GridColumn();
            this.colARSaleOrderNo = new DevExpress.XtraGrid.Columns.GridColumn();
            this.colCustomerName = new DevExpress.XtraGrid.Columns.GridColumn();
            this.colARSaleOrderMatchCode01 = new DevExpress.XtraGrid.Columns.GridColumn();
            this.colARSaleOrderMatchCode02 = new DevExpress.XtraGrid.Columns.GridColumn();
            this.colARSaleOrderStatus = new DevExpress.XtraGrid.Columns.GridColumn();
            this.colFK_ARCustomerID = new DevExpress.XtraGrid.Columns.GridColumn();
            this.colLockStatus = new DevExpress.XtraGrid.Columns.GridColumn();
            this.fld_btnOK = new DevExpress.XtraEditors.SimpleButton();
            this.fld_btnCancel = new DevExpress.XtraEditors.SimpleButton();
            this.label1 = new System.Windows.Forms.Label();
            this.fld_txtARSaleOrderNo = new DevExpress.XtraEditors.TextEdit();
            this.label3 = new System.Windows.Forms.Label();
            this.fld_txtARSaleOrderMC1 = new DevExpress.XtraEditors.TextEdit();
            this.label4 = new System.Windows.Forms.Label();
            this.fld_txtARSaleOrderMC2 = new DevExpress.XtraEditors.TextEdit();
            this.fld_txtSearch = new DevExpress.XtraEditors.SimpleButton();
            this.label5 = new System.Windows.Forms.Label();
            this.fld_dteARSaleOrderStartDateFrom = new DevExpress.XtraEditors.DateEdit();
            this.fld_dteARSaleOrderStartDateTo = new DevExpress.XtraEditors.DateEdit();
            this.label6 = new System.Windows.Forms.Label();
            this.fld_dteARSaleOrderDeliveryDateTo = new DevExpress.XtraEditors.DateEdit();
            this.label7 = new System.Windows.Forms.Label();
            this.fld_dteARSaleOrderDeliveryDateFrom = new DevExpress.XtraEditors.DateEdit();
            this.label8 = new System.Windows.Forms.Label();
            ((System.ComponentModel.ISupportInitialize)(this.fld_dgcSaleOrders)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.fld_dgvSaleOrders)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.repItemCheckEditSelect)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.fld_txtARSaleOrderNo.Properties)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.fld_txtARSaleOrderMC1.Properties)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.fld_txtARSaleOrderMC2.Properties)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.fld_dteARSaleOrderStartDateFrom.Properties.VistaTimeProperties)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.fld_dteARSaleOrderStartDateFrom.Properties)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.fld_dteARSaleOrderStartDateTo.Properties.VistaTimeProperties)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.fld_dteARSaleOrderStartDateTo.Properties)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.fld_dteARSaleOrderDeliveryDateTo.Properties.VistaTimeProperties)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.fld_dteARSaleOrderDeliveryDateTo.Properties)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.fld_dteARSaleOrderDeliveryDateFrom.Properties.VistaTimeProperties)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.fld_dteARSaleOrderDeliveryDateFrom.Properties)).BeginInit();
            this.SuspendLayout();
            // 
            // fld_dgcSaleOrders
            // 
            this.fld_dgcSaleOrders.EmbeddedNavigator.Name = "";
            this.fld_dgcSaleOrders.Location = new System.Drawing.Point(3, 111);
            this.fld_dgcSaleOrders.MainView = this.fld_dgvSaleOrders;
            this.fld_dgcSaleOrders.Name = "fld_dgcSaleOrders";
            this.fld_dgcSaleOrders.RepositoryItems.AddRange(new DevExpress.XtraEditors.Repository.RepositoryItem[] {
            this.repItemCheckEditSelect});
            this.fld_dgcSaleOrders.Size = new System.Drawing.Size(658, 252);
            this.fld_dgcSaleOrders.TabIndex = 10;
            this.fld_dgcSaleOrders.ViewCollection.AddRange(new DevExpress.XtraGrid.Views.Base.BaseView[] {
            this.fld_dgvSaleOrders});
            this.fld_dgcSaleOrders.DoubleClick += new System.EventHandler(this.fld_dgcSaleOrders_DoubleClick);
            // 
            // fld_dgvSaleOrders
            // 
            this.fld_dgvSaleOrders.Columns.AddRange(new DevExpress.XtraGrid.Columns.GridColumn[] {
            this.colSelect,
            this.colARSaleOrderID,
            this.colARSaleOrderNo,
            this.colCustomerName,
            this.colARSaleOrderMatchCode01,
            this.colARSaleOrderMatchCode02,
            this.colARSaleOrderStatus,
            this.colFK_ARCustomerID,
            this.colLockStatus});
            this.fld_dgvSaleOrders.GridControl = this.fld_dgcSaleOrders;
            this.fld_dgvSaleOrders.Name = "fld_dgvSaleOrders";
            this.fld_dgvSaleOrders.OptionsSelection.EnableAppearanceFocusedCell = false;
            this.fld_dgvSaleOrders.OptionsSelection.MultiSelect = true;
            this.fld_dgvSaleOrders.OptionsView.ShowAutoFilterRow = true;
            this.fld_dgvSaleOrders.CustomUnboundColumnData += new DevExpress.XtraGrid.Views.Base.CustomColumnDataEventHandler(this.fld_dgvSaleOrders_CustomUnboundColumnData);
            // 
            // colSelect
            // 
            this.colSelect.ColumnEdit = this.repItemCheckEditSelect;
            this.colSelect.FieldName = "colSelect";
            this.colSelect.Name = "colSelect";
            this.colSelect.UnboundType = DevExpress.Data.UnboundColumnType.Boolean;
            // 
            // repItemCheckEditSelect
            // 
            this.repItemCheckEditSelect.AutoHeight = false;
            this.repItemCheckEditSelect.Name = "repItemCheckEditSelect";
            // 
            // colARSaleOrderID
            // 
            this.colARSaleOrderID.Caption = "Sale Order";
            this.colARSaleOrderID.FieldName = "ARSaleOrderID";
            this.colARSaleOrderID.Name = "colARSaleOrderID";
            this.colARSaleOrderID.OptionsColumn.AllowEdit = false;
            // 
            // colARSaleOrderNo
            // 
            this.colARSaleOrderNo.Caption = "SO No.";
            this.colARSaleOrderNo.FieldName = "ARSaleOrderNo";
            this.colARSaleOrderNo.Name = "colARSaleOrderNo";
            this.colARSaleOrderNo.OptionsColumn.AllowEdit = false;
            this.colARSaleOrderNo.Visible = true;
            this.colARSaleOrderNo.VisibleIndex = 0;
            this.colARSaleOrderNo.Width = 91;
            // 
            // colCustomerName
            // 
            this.colCustomerName.Caption = "Customer";
            this.colCustomerName.FieldName = "colCustomerName";
            this.colCustomerName.Name = "colCustomerName";
            this.colCustomerName.OptionsColumn.AllowEdit = false;
            this.colCustomerName.UnboundType = DevExpress.Data.UnboundColumnType.String;
            this.colCustomerName.Visible = true;
            this.colCustomerName.VisibleIndex = 3;
            this.colCustomerName.Width = 108;
            // 
            // colARSaleOrderMatchCode01
            // 
            this.colARSaleOrderMatchCode01.Caption = "MC 1";
            this.colARSaleOrderMatchCode01.FieldName = "ARSaleOrderMatchCode01";
            this.colARSaleOrderMatchCode01.Name = "colARSaleOrderMatchCode01";
            this.colARSaleOrderMatchCode01.OptionsColumn.AllowEdit = false;
            this.colARSaleOrderMatchCode01.Visible = true;
            this.colARSaleOrderMatchCode01.VisibleIndex = 1;
            this.colARSaleOrderMatchCode01.Width = 108;
            // 
            // colARSaleOrderMatchCode02
            // 
            this.colARSaleOrderMatchCode02.Caption = "MC 2";
            this.colARSaleOrderMatchCode02.FieldName = "ARSaleOrderMatchCode02";
            this.colARSaleOrderMatchCode02.Name = "colARSaleOrderMatchCode02";
            this.colARSaleOrderMatchCode02.OptionsColumn.AllowEdit = false;
            this.colARSaleOrderMatchCode02.Visible = true;
            this.colARSaleOrderMatchCode02.VisibleIndex = 2;
            this.colARSaleOrderMatchCode02.Width = 108;
            // 
            // colARSaleOrderStatus
            // 
            this.colARSaleOrderStatus.Caption = "Status";
            this.colARSaleOrderStatus.FieldName = "ARSaleOrderStatus";
            this.colARSaleOrderStatus.Name = "colARSaleOrderStatus";
            this.colARSaleOrderStatus.Visible = true;
            this.colARSaleOrderStatus.VisibleIndex = 4;
            this.colARSaleOrderStatus.Width = 108;
            // 
            // colFK_ARCustomerID
            // 
            this.colFK_ARCustomerID.Caption = "Customer ID";
            this.colFK_ARCustomerID.FieldName = "FK_ARCustomerID";
            this.colFK_ARCustomerID.Name = "colFK_ARCustomerID";
            // 
            // colLockStatus
            // 
            this.colLockStatus.Caption = "Lock Status";
            this.colLockStatus.FieldName = "colLockStatus";
            this.colLockStatus.Name = "colLockStatus";
            this.colLockStatus.UnboundType = DevExpress.Data.UnboundColumnType.String;
            this.colLockStatus.Visible = true;
            this.colLockStatus.VisibleIndex = 5;
            this.colLockStatus.Width = 118;
            // 
            // fld_btnOK
            // 
            this.fld_btnOK.Location = new System.Drawing.Point(505, 369);
            this.fld_btnOK.Name = "fld_btnOK";
            this.fld_btnOK.Size = new System.Drawing.Size(75, 20);
            this.fld_btnOK.TabIndex = 11;
            this.fld_btnOK.Text = "&OK";
            this.fld_btnOK.Click += new System.EventHandler(this.fld_btnOK_Click);
            // 
            // fld_btnCancel
            // 
            this.fld_btnCancel.Location = new System.Drawing.Point(586, 369);
            this.fld_btnCancel.Name = "fld_btnCancel";
            this.fld_btnCancel.Size = new System.Drawing.Size(75, 20);
            this.fld_btnCancel.TabIndex = 12;
            this.fld_btnCancel.Text = "&Cancel";
            this.fld_btnCancel.Click += new System.EventHandler(this.fld_btnCancel_Click);
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(0, 9);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(45, 13);
            this.label1.TabIndex = 13;
            this.label1.Text = "S.O No.";
            // 
            // fld_txtARSaleOrderNo
            // 
            this.fld_txtARSaleOrderNo.EditValue = "";
            this.fld_txtARSaleOrderNo.Location = new System.Drawing.Point(73, 6);
            this.fld_txtARSaleOrderNo.Name = "fld_txtARSaleOrderNo";
            this.fld_txtARSaleOrderNo.Size = new System.Drawing.Size(100, 20);
            this.fld_txtARSaleOrderNo.TabIndex = 14;
            // 
            // label3
            // 
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(0, 76);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(28, 13);
            this.label3.TabIndex = 17;
            this.label3.Text = "MC1";
            // 
            // fld_txtARSaleOrderMC1
            // 
            this.fld_txtARSaleOrderMC1.Location = new System.Drawing.Point(73, 73);
            this.fld_txtARSaleOrderMC1.Name = "fld_txtARSaleOrderMC1";
            this.fld_txtARSaleOrderMC1.Size = new System.Drawing.Size(100, 20);
            this.fld_txtARSaleOrderMC1.TabIndex = 18;
            // 
            // label4
            // 
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(202, 76);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(28, 13);
            this.label4.TabIndex = 19;
            this.label4.Text = "MC2";
            // 
            // fld_txtARSaleOrderMC2
            // 
            this.fld_txtARSaleOrderMC2.Location = new System.Drawing.Point(275, 73);
            this.fld_txtARSaleOrderMC2.Name = "fld_txtARSaleOrderMC2";
            this.fld_txtARSaleOrderMC2.Size = new System.Drawing.Size(100, 20);
            this.fld_txtARSaleOrderMC2.TabIndex = 20;
            // 
            // fld_txtSearch
            // 
            this.fld_txtSearch.Location = new System.Drawing.Point(586, 85);
            this.fld_txtSearch.Name = "fld_txtSearch";
            this.fld_txtSearch.Size = new System.Drawing.Size(75, 20);
            this.fld_txtSearch.TabIndex = 21;
            this.fld_txtSearch.Text = "&Search";
            this.fld_txtSearch.Click += new System.EventHandler(this.fld_txtSearch_Click);
            // 
            // label5
            // 
            this.label5.AutoSize = true;
            this.label5.Location = new System.Drawing.Point(0, 31);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(55, 13);
            this.label5.TabIndex = 22;
            this.label5.Text = "Date from";
            // 
            // fld_dteARSaleOrderStartDateFrom
            // 
            this.fld_dteARSaleOrderStartDateFrom.EditValue = null;
            this.fld_dteARSaleOrderStartDateFrom.Location = new System.Drawing.Point(73, 28);
            this.fld_dteARSaleOrderStartDateFrom.Name = "fld_dteARSaleOrderStartDateFrom";
            this.fld_dteARSaleOrderStartDateFrom.Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
            new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)});
            this.fld_dteARSaleOrderStartDateFrom.Properties.VistaTimeProperties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
            new DevExpress.XtraEditors.Controls.EditorButton()});
            this.fld_dteARSaleOrderStartDateFrom.Size = new System.Drawing.Size(100, 20);
            this.fld_dteARSaleOrderStartDateFrom.TabIndex = 23;
            // 
            // fld_dteARSaleOrderStartDateTo
            // 
            this.fld_dteARSaleOrderStartDateTo.EditValue = null;
            this.fld_dteARSaleOrderStartDateTo.Location = new System.Drawing.Point(275, 28);
            this.fld_dteARSaleOrderStartDateTo.Name = "fld_dteARSaleOrderStartDateTo";
            this.fld_dteARSaleOrderStartDateTo.Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
            new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)});
            this.fld_dteARSaleOrderStartDateTo.Properties.VistaTimeProperties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
            new DevExpress.XtraEditors.Controls.EditorButton()});
            this.fld_dteARSaleOrderStartDateTo.Size = new System.Drawing.Size(100, 20);
            this.fld_dteARSaleOrderStartDateTo.TabIndex = 25;
            // 
            // label6
            // 
            this.label6.AutoSize = true;
            this.label6.Location = new System.Drawing.Point(202, 31);
            this.label6.Name = "label6";
            this.label6.Size = new System.Drawing.Size(17, 13);
            this.label6.TabIndex = 24;
            this.label6.Text = "to";
            // 
            // fld_dteARSaleOrderDeliveryDateTo
            // 
            this.fld_dteARSaleOrderDeliveryDateTo.EditValue = null;
            this.fld_dteARSaleOrderDeliveryDateTo.Location = new System.Drawing.Point(275, 50);
            this.fld_dteARSaleOrderDeliveryDateTo.Name = "fld_dteARSaleOrderDeliveryDateTo";
            this.fld_dteARSaleOrderDeliveryDateTo.Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
            new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)});
            this.fld_dteARSaleOrderDeliveryDateTo.Properties.VistaTimeProperties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
            new DevExpress.XtraEditors.Controls.EditorButton()});
            this.fld_dteARSaleOrderDeliveryDateTo.Size = new System.Drawing.Size(100, 20);
            this.fld_dteARSaleOrderDeliveryDateTo.TabIndex = 29;
            // 
            // label7
            // 
            this.label7.AutoSize = true;
            this.label7.Location = new System.Drawing.Point(202, 53);
            this.label7.Name = "label7";
            this.label7.Size = new System.Drawing.Size(17, 13);
            this.label7.TabIndex = 28;
            this.label7.Text = "to";
            // 
            // fld_dteARSaleOrderDeliveryDateFrom
            // 
            this.fld_dteARSaleOrderDeliveryDateFrom.EditValue = null;
            this.fld_dteARSaleOrderDeliveryDateFrom.Location = new System.Drawing.Point(73, 50);
            this.fld_dteARSaleOrderDeliveryDateFrom.Name = "fld_dteARSaleOrderDeliveryDateFrom";
            this.fld_dteARSaleOrderDeliveryDateFrom.Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
            new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)});
            this.fld_dteARSaleOrderDeliveryDateFrom.Properties.VistaTimeProperties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
            new DevExpress.XtraEditors.Controls.EditorButton()});
            this.fld_dteARSaleOrderDeliveryDateFrom.Size = new System.Drawing.Size(100, 20);
            this.fld_dteARSaleOrderDeliveryDateFrom.TabIndex = 27;
            // 
            // label8
            // 
            this.label8.AutoSize = true;
            this.label8.Location = new System.Drawing.Point(0, 53);
            this.label8.Name = "label8";
            this.label8.Size = new System.Drawing.Size(77, 13);
            this.label8.TabIndex = 26;
            this.label8.Text = "Ship date from";
            // 
            // guiSelectTransfer
            // 
            this.Appearance.BackColor = System.Drawing.SystemColors.Control;
            this.Appearance.Options.UseBackColor = true;
            this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
            this.ClientSize = new System.Drawing.Size(664, 394);
            this.ControlBox = true;
            this.Controls.Add(this.fld_dteARSaleOrderDeliveryDateTo);
            this.Controls.Add(this.label7);
            this.Controls.Add(this.fld_dteARSaleOrderDeliveryDateFrom);
            this.Controls.Add(this.label8);
            this.Controls.Add(this.fld_dteARSaleOrderStartDateTo);
            this.Controls.Add(this.label6);
            this.Controls.Add(this.fld_dteARSaleOrderStartDateFrom);
            this.Controls.Add(this.label5);
            this.Controls.Add(this.fld_txtARSaleOrderMC2);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.fld_txtSearch);
            this.Controls.Add(this.fld_txtARSaleOrderMC1);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.fld_txtARSaleOrderNo);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.fld_btnCancel);
            this.Controls.Add(this.fld_btnOK);
            this.Controls.Add(this.fld_dgcSaleOrders);
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.Office2003;
            this.LookAndFeel.UseDefaultLookAndFeel = false;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "guiSelectTransfer";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
            this.Tag = "SS";
            this.Text = "Sale Order";
            this.Load += new System.EventHandler(this.guiSelectSaleOrder_Load);
            this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.guiSelectSaleOrder_FormClosed);
            this.Controls.SetChildIndex(this.fld_dgcSaleOrders, 0);
            this.Controls.SetChildIndex(this.fld_btnOK, 0);
            this.Controls.SetChildIndex(this.fld_btnCancel, 0);
            this.Controls.SetChildIndex(this.label1, 0);
            this.Controls.SetChildIndex(this.fld_txtARSaleOrderNo, 0);
            this.Controls.SetChildIndex(this.label3, 0);
            this.Controls.SetChildIndex(this.fld_txtARSaleOrderMC1, 0);
            this.Controls.SetChildIndex(this.fld_txtSearch, 0);
            this.Controls.SetChildIndex(this.label4, 0);
            this.Controls.SetChildIndex(this.fld_txtARSaleOrderMC2, 0);
            this.Controls.SetChildIndex(this.label5, 0);
            this.Controls.SetChildIndex(this.fld_dteARSaleOrderStartDateFrom, 0);
            this.Controls.SetChildIndex(this.label6, 0);
            this.Controls.SetChildIndex(this.fld_dteARSaleOrderStartDateTo, 0);
            this.Controls.SetChildIndex(this.label8, 0);
            this.Controls.SetChildIndex(this.fld_dteARSaleOrderDeliveryDateFrom, 0);
            this.Controls.SetChildIndex(this.label7, 0);
            this.Controls.SetChildIndex(this.fld_dteARSaleOrderDeliveryDateTo, 0);
            ((System.ComponentModel.ISupportInitialize)(this.fld_dgcSaleOrders)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.fld_dgvSaleOrders)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.repItemCheckEditSelect)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.fld_txtARSaleOrderNo.Properties)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.fld_txtARSaleOrderMC1.Properties)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.fld_txtARSaleOrderMC2.Properties)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.fld_dteARSaleOrderStartDateFrom.Properties.VistaTimeProperties)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.fld_dteARSaleOrderStartDateFrom.Properties)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.fld_dteARSaleOrderStartDateTo.Properties.VistaTimeProperties)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.fld_dteARSaleOrderStartDateTo.Properties)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.fld_dteARSaleOrderDeliveryDateTo.Properties.VistaTimeProperties)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.fld_dteARSaleOrderDeliveryDateTo.Properties)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.fld_dteARSaleOrderDeliveryDateFrom.Properties.VistaTimeProperties)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.fld_dteARSaleOrderDeliveryDateFrom.Properties)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }
        #endregion
        

        public String ShipmentType
        {
            get
            {
                return _shipmentType;
            }

            set
            {
                _shipmentType = value;
            }
        }

        public guiSelectTransfer(BaseModuleERP mdl, String strShipmentType)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
            Module = mdl;
            ShipmentType = strShipmentType;
        }

        #region Utility Functions      

        private bool SelectSaleOrder(int iARSaleOrderID)
        {
            if (THSUtil.ObjectIsEditingByOtherUser("SaleOrder", iARSaleOrderID))
            {
                MessageBox.Show("This Sale Order being lock!", "#Message#", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
            else
            {
                ShipmentEntities entity = (ShipmentEntities)((BaseModuleERP)Module).CurrentModuleEntity;

                ICShipmentSaleOrdersInfo objICShipmentSaleOrdersInfo = new ICShipmentSaleOrdersInfo();
                objICShipmentSaleOrdersInfo.FK_ARSaleOrderID = iARSaleOrderID;
                objICShipmentSaleOrdersInfo.Position = entity.ICShipmentSaleOrdersList.Count;
                entity.ICShipmentSaleOrdersList.Add(objICShipmentSaleOrdersInfo);

                
                ARSaleOrdersInfo objARSaleOrdersInfo= (ARSaleOrdersInfo) new ARSaleOrdersController().GetObjectByID(iARSaleOrderID);
                entity.GenerateEntity(objARSaleOrdersInfo);
                
                ((ShipmentModule)Module)._uiInformation.CalculateTotalInformation();

                //((ShipmentModule)Module).SetEnablesOfNotEditControls(false);
                return true;
            }
        }

        private void LockSelectedSaleOrders()
        {
            GEUserAuditsController objGEUserAuditsController = new GEUserAuditsController();

            //Get ADUserID            
            int iADUserID = new ADUsersController().GetObjectIDByName(THSApp.CurrentUser);

            ShipmentEntities entity = (ShipmentEntities)((BaseModuleERP)Module).CurrentModuleEntity;
            foreach (ICShipmentSaleOrdersInfo objICShipmentSaleOrdersInfo in entity.ICShipmentSaleOrdersList)
            {
                GEUserAuditsInfo objGEUserAuditsInfo = new GEUserAuditsInfo();
                objGEUserAuditsInfo.ADUserID = iADUserID;
                objGEUserAuditsInfo.ADUserName = THSApp.CurrentUser;
                objGEUserAuditsInfo.GEUserAuditModuleName = "SaleOrder";
                objGEUserAuditsInfo.GEUserAuditBeginDate = DateTime.Now;
                objGEUserAuditsInfo.GEUserAuditAction = BaseToolbar.ModusEdit;
                objGEUserAuditsInfo.GEUserAuditParameter = objICShipmentSaleOrdersInfo.FK_ARSaleOrderID.ToString();

                objGEUserAuditsController.CreateObject(objGEUserAuditsInfo);
            }
        }

        #endregion        

        #region Windows event handler functions
        private void guiSelectSaleOrder_Load(object sender, EventArgs e)
        {            
            fld_txtARSaleOrderNo.DataBindings.Add(new Binding("Text",_saleOrderSearchObject,"ARSaleOrderNo",true, DataSourceUpdateMode.OnPropertyChanged));

            fld_txtARSaleOrderMC1.DataBindings.Add(new Binding("Text", _saleOrderSearchObject, "ARSaleOrderMatchCode01Combo", true, DataSourceUpdateMode.OnPropertyChanged));
            fld_txtARSaleOrderMC2.DataBindings.Add(new Binding("Text", _saleOrderSearchObject, "ARSaleOrderMatchCode02Combo", true, DataSourceUpdateMode.OnPropertyChanged));
            fld_dteARSaleOrderStartDateFrom.DataBindings.Add(new Binding("EditValue", _saleOrderSearchObject, "ARSaleOrderStartDateFrom", true, DataSourceUpdateMode.OnPropertyChanged));
            fld_dteARSaleOrderStartDateTo.DataBindings.Add(new Binding("EditValue", _saleOrderSearchObject, "ARSaleOrderStartDateTo", true, DataSourceUpdateMode.OnPropertyChanged));
            fld_dteARSaleOrderDeliveryDateFrom.DataBindings.Add(new Binding("EditValue", _saleOrderSearchObject, "ARSaleOrderDeliveryDateFrom", true, DataSourceUpdateMode.OnPropertyChanged));
            fld_dteARSaleOrderDeliveryDateTo.DataBindings.Add(new Binding("EditValue", _saleOrderSearchObject, "ARSaleOrderDeliveryDateTo", true, DataSourceUpdateMode.OnPropertyChanged));
            
            fld_dteARSaleOrderStartDateFrom.DateTime = THSUtil.GetYearBeginDate();
            fld_dteARSaleOrderStartDateTo.DateTime = THSUtil.GetYearEndDate();
            fld_dteARSaleOrderDeliveryDateFrom.DateTime = THSUtil.GetYearBeginDate();
            fld_dteARSaleOrderDeliveryDateTo.DateTime = THSUtil.GetYearEndDate();
            
        }

        private void fld_btnCancel_Click(object sender, EventArgs e)
        {            
            this.Close();            
        }

        

        private void fld_btnOK_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            ShipmentEntities entity = (ShipmentEntities)((BaseModuleERP)Module).CurrentModuleEntity;
            int iRowHandle = fld_dgvSaleOrders.FocusedRowHandle;
            if (iRowHandle >= 0)
            {
                int iARSaleOrderID = Convert.ToInt32(fld_dgvSaleOrders.GetRowCellValue(iRowHandle, colARSaleOrderID));
                if (!SelectSaleOrder(iARSaleOrderID))                    
                    return;                               
            }
            Cursor.Current = Cursors.Default;
            LockSelectedSaleOrders();
            this.Close();
        }

        private void fld_dgcSaleOrders_DoubleClick(object sender, EventArgs e)
        {
            DevExpress.XtraGrid.GridControl gridControl = sender as DevExpress.XtraGrid.GridControl;
            DevExpress.XtraGrid.Views.Grid.GridView gridView = gridControl.Views[0] as DevExpress.XtraGrid.Views.Grid.GridView;
            DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo hi = new DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo();
            hi = gridView.CalcHitInfo(gridControl.PointToClient(Control.MousePosition));
            int iRowHandle = hi.RowHandle;
            if (iRowHandle >= 0)
            {
                Cursor.Current = Cursors.WaitCursor;
                int iARSaleOrderID = Convert.ToInt32(fld_dgvSaleOrders.GetRowCellValue(iRowHandle, colARSaleOrderID));
                if (!SelectSaleOrder(iARSaleOrderID))
                    return;
            }
            Cursor.Current = Cursors.Default;
            LockSelectedSaleOrders();

            this.Close();
        }

        private void fld_dgvSaleOrders_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
        {
            if (e.Column == colCustomerName)
            {
                if (e.IsGetData)
                {
                    int iARCustomerID = Convert.ToInt32(fld_dgvSaleOrders.GetRowCellValue(e.RowHandle, colFK_ARCustomerID));
                    String strMACustomerName = new ARCustomersController().GetObjectNameByID(iARCustomerID);
                    e.Value = strMACustomerName;
                }
            }
            if (e.Column == colLockStatus)
            {
                if (e.IsGetData)
                {
                    int iARSaleOrderID = Convert.ToInt32(fld_dgvSaleOrders.GetRowCellValue(e.RowHandle, colARSaleOrderID));
                    if (THSUtil.ObjectIsEditingByOtherUser("SaleOrder", iARSaleOrderID))
                        e.Value = "Locked";
                    else
                        e.Value = "UnLock";
                }
            }
        }

        private void fld_txtSearch_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                ARSaleOrdersController objARSaleOrdersController = new ARSaleOrdersController();
                _saleOrderSearchObject.ARSaleOrderStatus = SaleOrder.SaleOrderModule.cstSaleOrderStatusNew;
                DataSet dsSaleOrderNew = objARSaleOrdersController.SearchObject(_saleOrderSearchObject);

                _saleOrderSearchObject.ARSaleOrderStatus = SaleOrder.SaleOrderModule.cstSaleOrderStatusIncomplete;
                DataSet dsSaleOrderIncomplete = objARSaleOrdersController.SearchObject(_saleOrderSearchObject);

                //
                DataTable tblARSaleOrders = dsSaleOrderNew.Tables[0];
                foreach (DataRow rowSaleOrderIncomplete in dsSaleOrderIncomplete.Tables[0].Rows)
                {
                    
                    tblARSaleOrders.Rows.Add(rowSaleOrderIncomplete.ItemArray);
                }

                BindingSource bds = new BindingSource();
                bds.DataSource = tblARSaleOrders;

                fld_dgcSaleOrders.DataSource = bds;

                dsSaleOrderNew.Dispose();
                dsSaleOrderIncomplete.Dispose();

                Cursor.Current = Cursors.Default;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        #endregion       

        private void guiSelectSaleOrder_FormClosed(object sender, FormClosedEventArgs e)
        {
            ShipmentEntities entity = (ShipmentEntities)((ShipmentModule)Module).CurrentModuleEntity;
            if (entity.ICShipmentSaleOrdersList.Count <= 0)
                ((ShipmentModule)Module).ActionCancel();
        }

        
    }
}

